<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline>
            <el-form-item label="奖励对象：">
              <el-input v-model="tableFrom.name" placeholder="请输入" class="selWidth" clearable/>
            </el-form-item>
            <el-select v-model="tableFrom.isPass" placeholder="状态" clearable class="selWidth">
                    <el-option label="未审核" :value="0"></el-option>
                    <el-option label="通过" :value="1"></el-option>
                    <el-option label="不通过" :value="2"></el-option>
                  </el-select>

            <el-button type="primary" icon="el-icon-search" @click="getList(1)">搜索</el-button>
          </el-form>
        </div>


      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"

        size="mini"
        ref="multipleTable"
        :header-cell-style=" {fontWeight:'bold'}"
      >
        <!-- <el-table-column label="序号"  type="index" /> -->
        <el-table-column prop="optionName" label="积分事项"/>

        <el-table-column prop="integral" label="积分数"/>
        <el-table-column prop="isPass" label="审核状态">
          <template slot-scope="scope">

            <span v-if="scope.row.isPass==0">待审核</span>
            <span v-if="scope.row.isPass==1">审核通过</span>
            <span v-if="scope.row.isPass==2">审核不通过</span>

          </template>
        </el-table-column>
        <el-table-column prop="name" label="奖励对象"/>
        <el-table-column prop="reason" label="事项说明"/>

        <el-table-column prop="type" label="积分类型">
          <template slot-scope="scope">
            <span v-if="scope.row.type==1">增加</span>
            <span v-if="scope.row.type==2">扣减</span>

          </template>
        </el-table-column>

        <el-table-column prop="name" label="奖励对象"/>

        <el-table-column label="操作" min-width="200" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button type="text" v-if="scope.row.isPass==0" size="small" @click="handleEdit(scope.row)">审核</el-button>
            <el-button type="text" v-else size="small" @click="handleEdit(scope.row)">查看</el-button>

          </template>
        </el-table-column>
      </el-table>
      <div class="block mb20">
        <el-pagination
          :page-sizes="[10, 20, 30, 40]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>

    <el-dialog
      :title="isCreate===0 ? '添加数据' : '编辑数据'"
      :visible.sync="dialogVisible"
      width="1200px"
      :before-close="handleClose"
      v-if="dialogVisible"
    >
      <div v-loading="loading">
        <restaurantDialog ref="restaurantDialog" :isCreate='isCreate' :categoryOptions='categoryOptions' :selectItem='selectItem' @getList='getList(1)' @close='handleClose'></restaurantDialog>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import restaurantDialog from './restaurantDialog'
  import{getAppList,homeGetDelete}from '@/api/village'
  
  export default {
    name: "advertisingSpaceManage",
    components: { restaurantDialog },
    data() {
      return {
        time:undefined,
        dialogVisible: false,
        isCreate: 0,
        selectItem:undefined,
        listLoading: true,
        tableData: {
          data: [],
          total: 0
        },
        tableFrom: {
          page: 1,
          limit: 20,
          name:undefined,//名称
          isShow:undefined,//抢购状态
        },
        loading: false,
        categoryOptions:[]
      }
    },
    mounted() {
     this.getList()
    },
    methods: {
      // 删除
      handleDelete(id, idx) {
        // let data={
        //   id:id
        // }
        this.$modalSure().then(() => {
          homeGetDelete({id:id}).then(() => {
            this.$message.success('删除成功')
            this.tableData.data.splice(idx, 1)
          })
        })
      },

      // 编辑
      handleEdit(row) {
        this.selectItem = row
        this.isCreate = 1
        this.dialogVisible = true
      },

      // 列表
      getList(num) {
        this.listLoading = true
        this.tableFrom.page = num ? num : this.tableFrom.page;
        getAppList(this.tableFrom).then(res => {
          console.log(res,'ddd')
          this.tableData.data = res.list
          this.tableData.total = res.total
          this.tableData.data.map(item => this.$set(item, 'isEdit', false))
          this.listLoading = false
        }).catch((res) => {
          this.listLoading = false
        })
      },
      pageChange(page) {
        this.tableFrom.page = page
        this.getList()
      },
      handleSizeChange(val) {
        this.tableFrom.limit = val
        this.getList()
      },
      handleStatusChange(id,name){
        if(name === '上架'){
          postCateringStatus({ ids: id,isShow:1 }).then(() => {
            this.getList(1)
          })
        }

        if(name === '下架'){
          postCateringStatus({ ids: id,isShow:0 }).then(() => {
            this.getList(1)
          })
        }
      },
      add() {
        this.selectItem = undefined
        this.isCreate = 0
        this.dialogVisible = true
      },
      handleClose() {
        this.dialogVisible = false
      },

      //跳转套餐
      handleView(id){
        this.$router.push(`/family/restaurantManage2?id=${id}`);
      }
    }
  }
</script>

<style scoped>

</style>
